package main

import (
	"fmt"
	"github.com/valyala/fasthttp"
	"google.golang.org/protobuf/proto"
	pb "t_proto/protos/proto"
)

// 获取post的请求json数据
func ptoTestPost(ctx *fasthttp.RequestCtx) {

	body:=ctx.PostBody()
	req:=&pb.Req{}
	err:=proto.Unmarshal(body,req)
	if err!=nil{
		fmt.Println("解析错误：",err)
		return
	}

	fmt.Printf("服务器接收到的参数：%+v === \n",req)

	// 构建返回值
	resp:=	&pb.Resp{
		Text: "你猜你猜你猜……",
		Index: 10000,
	}

	respBody,err:=proto.Marshal(resp)
	if err!=nil{
		fmt.Println("解析错误：",err)
		return
	}

	fmt.Println(respBody)

	fmt.Fprint(ctx, string(respBody))

}
